<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>

<script>
   
   var data = [
       {
           name: '中国',
           children: [
               {
                   name: '教第三节课',

               },
               {
                   name: '教呼呼',
                   children: [
                       {
                           name: '大一',
                           children: [
                               {
                                   name: '课程1',
                                   children: [
                                       {
                                           name: '1231'
                                       },
                                       {
                                           name: '121'
                                       }
                                   ]
                               },
                               {
                                   name: '课程2',
                                   children: [
                                       {
                                           name: '1232'
                                       },
                                       {
                                           name: '122'
                                       }
                                   ]
                               },
                               {
                                   name: '课程3',
                                   children: [
                                       {
                                           name: '1233'
                                       },
                                       {
                                           name: '123'
                                       }
                                   ]
                               },

                           ]
                       }
                   ]
               },
               {
                   name: '活动',
                   children:null
               }
           ]
       }
   ];
        

function recursive(obj) {
    var output = '';
    if (typeof obj === 'object') {
        for (var key in obj) {
            var item = obj[key];
            if (typeof item === 'object') {
                output += recursive(item);
            } else {
                output += key + ':' + item + '\n';
            }
        }
    } else {
        output += obj + '\n';
    }
    return output;
}

var name = recursive(data)   
console.log(name)
</script>
	
</body>
</html>